package physics;

import java.io.Serializable;

public class Vector implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public enum Type{
		FORCE_NORMAL, FORCE_GRAVITY, FORCE_ELECTRIC, FORCE_MAGNETIC, VELOCITY, MOMENTUM, FORCE_SPRING
	}
	
	private Type t;
	private Location position;
	private double xMag;
	
	private double yMag;
	private double theta;
	public Vector() {
		this(new Location(), null, 0, 0);
	}
	public Vector(Location pos, Type t, double xMagnitude, double yMagnitude) {
		this.t = t;
		position = pos;
		xMag = xMagnitude;
		yMag = yMagnitude;
		this.theta = Math.atan(yMag/xMag);
	}
	public Vector(Location pos, Type t, double Magnitude, double dir, boolean isPolar){
		this.t = t;
		position = pos;
		xMag = Magnitude*Math.cos(dir);
		yMag = Magnitude*Math.sin(dir);
		theta = dir;
	}
	public Type getType() {
		return t;
	}
	public Vector toType(Type t) {
		return new Vector(position, t, xMag, yMag);
	}
	public Vector add(Vector v) {
		return new Vector(position,t,xMag+v.xMag,yMag+v.yMag);
	}
	public Vector subtract(Vector v) {
		return new Vector(position,t,xMag-v.xMag,yMag-v.yMag);
	}
	public Location getLocation() {
		return position;
	}
	public Vector divide(double d) {
		return new Vector(position,t,xMag/d,yMag/d);
	}
	public Vector multiply(double d) {
		return new Vector(position,t,xMag*d,yMag*d);
	}
	public double getXMag(){
		return xMag;
	}
	public double getYMag(){
		return yMag;
	}
	public double getNetMag(){
		return Math.sqrt(Math.pow(xMag,2)+Math.pow(yMag,2));
	}
	public double getAngle() {
		return theta;
	}
	public Vector unit() {
		return getNetMag() == 0 ? this : divide(getNetMag());
	}
	public String toString(){
		return ""+ getNetMag() +" "+xMag +" "+ yMag;
	}
	public double dot(Vector v) {
		return getXMag()*v.getXMag()+getYMag()*v.getYMag();
	}
}
